﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Arroguella.Utilities;

namespace Arroguella.Screens
{
    public class Screen
    {
        #region Constructor

        protected Screen(EventHandler theScreenEvent, GraphicsDevice graphicsDevice, Arroguella arroguella)
        {
            Arroguella = arroguella;

            ScreenEvent = theScreenEvent;

            this.graphicsDevice = graphicsDevice;
        }

        #endregion

        #region Events

        /// <summary>
        /// The event associated with the Screen.
        /// This event is used to raise events back in the main game class
        /// to notify the game that something has changed
        /// or needs to be changed
        /// </summary>
        protected EventHandler ScreenEvent;        

        #endregion

        #region Methods

        //Update any information specific to the screen
        public virtual void Update(GameTime theTime)
        {
        }

        //Draw any objects specific to the screen
        public virtual void Draw(SpriteBatch theBatch)
        {
        }

        /// <summary>
        /// Draws the background color,
        /// and then draws the background texture if it exists.
        /// </summary>
        internal void DrawBackground(SpriteBatch spriteBatch)
        {
            Utils.DrawBackgroundColor(BackgroundColor, spriteBatch, graphicsDevice);

            if (Background != null)
            {
                spriteBatch.Draw(Background, Vector2.Zero, Color.White);
            }
        }

        #endregion

        #region Properties

        protected readonly Arroguella Arroguella;

        /// <summary>
        /// Stores the PlayerIndex for the controlling player, i.e. Player One
        /// </summary>
        protected static PlayerIndex PlayerOne;

        private readonly GraphicsDevice graphicsDevice;

        /// <summary>
        /// The background of the screen
        /// </summary>
        internal Texture2D Background { get; set; }

        /// <summary>
        /// The background color of the screen.
        /// </summary>
        internal Color BackgroundColor = Color.Black;

        protected Rectangle TitleSafeArea { get { return graphicsDevice.Viewport.TitleSafeArea; } }

        #endregion
    }
}
